package com.example.demo.controller;

import cn.hutool.core.bean.BeanUtil;
import com.example.demo.entity.DTO.FosterDTO;
import com.example.demo.entity.Foster;
import com.example.demo.entity.VO.FosterVO;
import com.example.demo.result.Result;
import com.example.demo.service.IFosterService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 寄养表 前端控制器
 * </p>
 *
 * @author Mr.sdy
 * @since 2024-06-05
 */
@Api(tags = "寄养接口")
@RestController
@RequestMapping("/foster")
public class FosterController {

    @Resource
    private IFosterService fosterService;

    @ApiOperationSupport(author = "Mr.sdy")
    @ApiOperation(value = "通过userId查询所有寄养数据")
    @GetMapping("/findAllFostersByUserId")
/*    @SaCheckLogin*/
    public Result<List<FosterDTO>> findAllFostersByUserId(@RequestParam Integer userId) {
        return Result.success(fosterService.selectFostersByUserId(userId)).msg("查询成功");
    }

    /**
     * 新增
     * @param
     * @return
     */
    @ApiOperationSupport(author = "Mr.sdy")
    @ApiOperation(value = "新增")
    @PostMapping("/add")
    public Result<String> add(@RequestBody FosterVO fosterVO) {
        Foster foster = new Foster();
        BeanUtil.copyProperties(fosterVO,foster);
        if(!fosterService.insert(foster)){
            return Result.error().msg("添加寄养订单失败");
        }
        return Result.success().msg("添加寄养订单成功");
    }
}